import {Injectable} from '@angular/core';
import {Observable} from 'rxjs';
import {
    CanDeactivate,
    ActivatedRouteSnapshot,
    RouterStateSnapshot
} from '@angular/router';
import {HomeComponent} from "../pages/home.component";

export interface CanComponentDeactivate {
    canDeactivate: () => Observable<boolean> | Promise<boolean> | boolean;
}

@Injectable({
    providedIn: 'root',
})
export class LeaveHomeGuard implements CanDeactivate<HomeComponent> {

    canDeactivate(
        homeComponent: HomeComponent,
        route: ActivatedRouteSnapshot,
        state: RouterStateSnapshot
    ): Observable<boolean> | boolean {
        homeComponent.homeService.scrollTop=document.documentElement.scrollTop;
        return true;
    }
}